//
//  VenderLoginView.m
//  MELive
//
//  Created by 曹曹 on 2016/10/19.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "VenderLoginView.h"
#import "UIView+Extension.h"

@implementation VenderLoginView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]){
        [self setupBasic];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupBasic];
    }
    return self;
}

- (void)setupBasic {
    [self createBtnWithImage:@"login_icon_weixin" tag:0];
    [self createBtnWithImage:@"login_icon_xinlang" tag:1];
    [self createBtnWithImage:@"login_icon_qq" tag:2];
}

- (UIButton *)createBtnWithImage:(NSString *)imageName tag:(NSInteger)tag {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    btn.tag = tag;
    //    自适应大小
//    [btn sizeToFit];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    return btn;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    NSInteger count = self.subviews.count;
    for (int i= 0; i < count; i++){
        UIButton *btn = self.subviews[i];
        btn.width = CGRectGetWidth(self.bounds) / 3.0;
        btn.height = CGRectGetHeight(self.bounds);
        CGFloat x = btn.width * i;
        CGFloat y = 0;
        btn.frame = CGRectMake(x, y, btn.width, btn.height);
    }
}

- (void)btnClick:(UIButton *)btn {
    if (self.selectedBlock){
        self.selectedBlock(btn.tag);
    }
}

@end
